Skip to content

fix: restore secure clipping to prevent landmass being cut at map edges#1385

Merged
Azgaar merged 2 commits intomasterfrom
copilot/fix-landmass-cut-map-edges
Apr 22, 2026
Merged

fix: restore secure clipping to prevent landmass being cut at map edges#1385
Azgaar merged 2 commits intomasterfrom
copilot/fix-landmass-cut-map-edges

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

Description

The f2fc427 resample-module refactor swapped window.polygonclip (custom, with a secure mode) for lineclip.clipPolygon and silently dropped the secure=1 call in featurePathRenderer. The secure mode added each boundary-crossing intersection point instead of 1×; without that multiplicity the curveBasisClosed B-spline arcs away from the map edge rather than tracking it, leaving an ocean-coloured gap along any border the landmass touches.

Before (seed=12):

Landmass cut along top edge

After (seed=12):

Landmass correctly fills to map edge

  • src/utils/commonUtils.ts — Add optional secure param to clipPoly. When set, each point that lands exactly on a map-boundary edge (x=0 | x=width | y=0 | y=height) is emitted 3× in the output, replicating the original B-spline knot-multiplicity behaviour that forces the curve to pass through the boundary.
  • src/renderers/draw-features.ts — Restore secure=1 in featurePathRenderer, matching the original getFeaturePath JS call.
  • src/utils/index.ts — Re-expose secure on window.clipPoly for legacy JS callers.

Copilot AI requested review from Copilot and removed request for Copilot April 22, 2026 13:50
Copilot AI linked an issue Apr 22, 2026 that may be closed by this pull request
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 22, 2026

Deploy Preview for afmg ready!

Name Link
🔨 Latest commit a97741c
🔍 Latest deploy log https://app.netlify.com/projects/afmg/deploys/69e8dc314cd30a00081686ba
😎 Deploy Preview https://deploy-preview-1385--afmg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

The f2fc427 refactor replaced window.polygonclip (which had a secure=1
mode) with lineclip.clipPolygon, removing the behavior that added each
boundary-crossing intersection point three times. Without this, the
curveBasisClosed B-spline arcs away from the map edges instead of
following them, leaving a visible ocean band at the map boundary.

Restore the secure parameter on clipPoly: when secure=1, boundary
points are duplicated twice after standard clipping, forcing the
B-spline to stay on the boundary. Re-expose the parameter on
window.clipPoly for legacy JS callers.

Agent-Logs-Url: https://github.com/Azgaar/Fantasy-Map-Generator/sessions/0b83756d-4055-4265-9258-c23b0a3681cd

Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 22, 2026 14:33
Copilot AI changed the title [WIP] Fix bug with landmass cut along the map edges fix: restore secure clipping to prevent landmass being cut at map edges Apr 22, 2026
Copilot AI requested a review from Azgaar April 22, 2026 14:36
@Azgaar Azgaar marked this pull request as ready for review April 22, 2026 14:51
Copilot AI review requested due to automatic review settings April 22, 2026 14:51
@Azgaar Azgaar merged commit 7c16f72 into master Apr 22, 2026
5 checks passed
@Azgaar Azgaar deleted the copilot/fix-landmass-cut-map-edges branch April 22, 2026 14:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores the legacy “secure clipping” behavior so landmass feature paths rendered with D3 curveBasisClosed stay pinned to the map boundary instead of bowing inward and leaving ocean-colored gaps at the edges.

Changes:

  • Added an optional secure parameter to clipPoly that duplicates boundary points to enforce B-spline knot multiplicity at map edges.
  • Restored secure clipping for feature path rendering by calling clipPoly(..., 1) in featurePathRenderer.
  • Re-exposed secure via window.clipPoly(points, secure?) for legacy JS callers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/utils/index.ts Updates the global window.clipPoly wrapper to accept an optional secure flag.
src/utils/commonUtils.ts Implements secure handling in clipPoly and updates the Window typing accordingly.
src/renderers/draw-features.ts Uses secure clipping for feature path rendering to avoid edge gaps.

Comment thread src/utils/commonUtils.ts
Comment on lines +12 to +44
* @param secure - When truthy, duplicate boundary-crossing points to prevent B-spline
* curves from arcing away from map edges (restores original "secure clipping" behavior)
* @returns Clipped polygon points
*/
export const clipPoly = (
points: [number, number][],
graphWidth: number,
graphHeight: number,
secure?: number,
) => {
if (points.length < 2) return points;
if (points.some((point) => point === undefined)) {
window.ERROR && console.error("Undefined point in clipPoly", points);
return points;
}

return clipPolygon(points, [0, 0, graphWidth, graphHeight]);
const clipped = clipPolygon(points, [0, 0, graphWidth, graphHeight]);

if (!secure || !clipped.length) return clipped;

// Duplicate each boundary point twice so the B-spline passes through it
// rather than arcing away from the map edge (replicates polygonclip secure=1)
const secured: [number, number][] = [];
for (const point of clipped) {
secured.push(point);
if (
point[0] === 0 ||
point[0] === graphWidth ||
point[1] === 0 ||
point[1] === graphHeight
) {
secured.push(point, point);
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation duplicates all points that lie on the map boundary, but the new JSDoc (and PR description) describe duplicating only boundary-crossing intersection points. If the intent is to match the original polygonclip secure=1 semantics more closely, consider detecting only the points introduced by clipping (or update the doc/PR description to reflect that all boundary points are triplicated).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Landmass is cut along the map edges

3 participants